<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of diadiemhoc_model
 *
 * @author Trung
 */
class M_diadiemhoc extends CI_Model {

    private $_name_table = 'tbl_diadiemhoc';
    private $_Ma_DiaDiemHoc = 'Ma_DiaDiemHoc';
    private $_TenCoSo = 'TenCoSo';
    private $_DiaChi = 'DiaChi';
    private $_Email = 'Email';
    private $_SoDienThoai = 'SoDienThoai';

    public function __construct() {
        parent::__construct();
       
    }

    public function getID() {
        $this->db->select_max($this->_Ma_DiaDiemHoc);
        $query = $this->db->get($this->_name_table);
        $data = $query->row_array();
        $id = $data->Ma_DiaDiemHoc;

        if (strlen($id) == 0) {
            $id = 'ADD0000';
        }
        $id++;

        return $id;
    }

    public function them() {
        $id = $this->getID();
        $ten = $this->getID();
        $diachi = $this->getID();
        $sdt = '0' . rand(1, 100) . rand(300000, 900000);
        $email = $ten . '@ctsv.fithou';
        $val = array($this->_Ma_DiaDiemHoc => $id,
            $this->_TenCoSo => $ten,
            $this->_DiaChi => $diachi,
            $this->_Email => $email,
            $this->_SoDienThoai => $sdt);

        $this->db->insert($this->_name_table, $val);
        return $val;
    }

    public function thems($n = 100) {
        $res[] = '';
        for ($i = 1; $i < $n; ++$i)
            $res[] = $this->them();
        return $res;
    }

    public function getAllId() {


        $this->db->select($this->_Ma_DiaDiemHoc)->from($this->_name_table);

        $query = $this->db->get();
        foreach ($query->result_array() as $value) {
            $id[] = $value[$this->_Ma_DiaDiemHoc];
        }

        return $id;
    }

}

?>
